﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using DflyingForum.Core.Framework;
using System.Xml.Linq;

namespace Core.Web.Code.UI
{
    public class PageInfo
    {
        //页面名称
        public string PageName { get; set; }
        //控件路径
        public string ControlPath { get; set; }
    }

    /// <summary>
    ///获取TemplateControl.xml配置文件的用户控件
    /// </summary>
    public class TemplateConfig
    {
        public TemplateConfig() { }

        public static IList<PageInfo> Pages
        {
            get
            {
                return GetPages();
            }
        }

        private static IList<PageInfo> GetPages()
        {
            //object o = DflyingCache.GetCache("CacheControl");//发现后来加点什么的获取不到 原来是缓存了 取消便于调试 记得要取消
            object o = null;
            IEnumerable<PageInfo> pages = null;
            if (o == null)
            {
                string xmlPath = HttpContext.Current.Server.MapPath("~/UI/TemplateConfig.xml");
                var doc = XElement.Load(xmlPath);
                pages = from item in doc.Elements("page")
                        select new PageInfo
                        {
                            PageName = item.Attribute("pagename").Value,
                            ControlPath = item.Attribute("controlpath").Value
                        };
                //DflyingCache.SetCache("CacheControl", pages.ToList());
            }
            return o as IList<PageInfo> ?? pages.ToList();
        }
    }
}